import {
  Component,
  OnInit,
  Input,
  ChangeDetectorRef,
  Output,
  EventEmitter,
} from "@angular/core";
import { PL00Error } from "../pl00-editor/PL00Error";
import { Observable, Subject } from "rxjs";

@Component({
  selector: "app-pl00-problems-panel",
  templateUrl: "./pl00-problems-panel.component.html",
  styleUrls: ["./pl00-problems-panel.component.css"],
})
export class Pl00ProblemsPanelComponent implements OnInit {
  errors: PL00Error[] = [];
  @Output() jumpToLine: EventEmitter<PL00Error> = new EventEmitter<PL00Error>();
  constructor(private cdf: ChangeDetectorRef) {}

  // 格式化错误
  formatError(error: PL00Error) {
    return (
      "第" +
      error.startLineNumber +
      "行 第" +
      error.startColumn +
      "列: " +
      error.message
    );
  }

  // 更新错误
  updateErrors(errors) {
    this.errors = errors;
    this.cdf.detectChanges();
  }

  // 点击具体的错误
  clickProblem(error) {
    this.jumpToLine.emit(error);
  }

  ngOnInit(): void {}
}
